/**
 * 系统平台
 * moonvip_admin
 * com.tz.web.adminuser
 * AdminUserController.java
 * 创建人:小胡
 * 时间：2016年11月19日 16:05:25
 *
 */
package com.tz.web.adminuser;

import com.tz.auth.AuthPassport;
import com.tz.bean.AdminUser;
import com.tz.bean.TzParams;
import com.tz.service.adminUser.IAdminUserService;
import com.tz.util.TmStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * 用户管理web
 * AdminUserController
 * 创建人:小胡
 * 时间：2016年11月19日 16:05:25
 * @version 1.0.0
 * 
 */
@Controller
@RequestMapping("/admin/adminuser")
public class AdminUserController {
	
	@Autowired
	private IAdminUserService adminuserService;

	/*列表查询*/
	@AuthPassport
	@RequestMapping("/list")
	public String list(TzParams params){
		return "adminuser/list";
	}

    /*模板页面*/
	@RequestMapping("/template")
	public String template(TzParams params ,Model model){
		params.setDeleteCode("001"); //过滤没有删除的数据
		model.addAttribute("datas", adminuserService.findAdminUsers(params));
		model.addAttribute("itemCount", adminuserService.count(params));
		return "adminuser/template";
	}

	@AuthPassport
	@RequestMapping(value="/add")
	public String add(){
		return "adminuser/add";
	}


	@AuthPassport
	@RequestMapping(value="/edit/{id}")
	public String edit(@PathVariable Integer id , Model model){
		//根据id 获取用户对象
		AdminUser adminUser =  adminuserService.get(id);
		model.addAttribute("adminUser" ,adminUser);
		return "adminuser/edit";
	}

	@AuthPassport
	@ResponseBody
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	public String delete(TzParams params){
		adminuserService.delete(params);
		return "success";
	}

	@ResponseBody
	@RequestMapping(value="/save")
	public int save(AdminUser adminuser){
		adminuser.setPassword(TmStringUtils.md5Base64(adminuser.getPassword()));
		int n = adminuserService.save(adminuser);
		return n;
	}

	@ResponseBody
	@RequestMapping(value="/update")
	public int update(AdminUser adminuser){
		adminuser.setUpdateTime(new Date());
		int n = adminuserService.update(adminuser);
		return n;
	}
}
